﻿using System;
using System.Linq;
using System.Linq.Expressions;

namespace SSTU.Helper
{
	/// <summary>
	/// Helper for working with property names and etc.
	/// </summary>
	public class PropertyHelper
	{
		/// <summary>
		/// Extracts the name of the property from expression in format '() => PropertyName'.
		/// </summary>
		/// <typeparam name="T">Type of the property result.</typeparam>
		/// <param name="propertyExpression">The property expression.</param>
		public static string ExtractPropertyName<T>(Expression<Func<T>> propertyExpression)
		{
			string propertyName = ((MemberExpression)propertyExpression.Body).Member.Name;
			return propertyName;
		}
	}
}
